
package cz.cvut.fel.y36mm1.videostreaming.client;

import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Graphics;
import javax.microedition.media.MediaException;
import javax.microedition.media.Player;
import javax.microedition.media.control.VideoControl;

/**
 * Screen displaying video seen through device's camera
 * @author Jiri Chadima, chadij1
 */
public class VideoCanvas extends Canvas {

	private VideoControl vc = null;
	private Player p = null;

	/**
	 * Sets up video on screen, if fullscreen is enabled, it is shown as fullscreen
	 * @param ctl	video control that was obtained from player
	 * @param pl	Player
	 */
	public void initControls(VideoControl ctl, Player pl) {
		int width = getWidth();
		int height = getHeight();
		this.vc = ctl;
		this.p = pl;

		vc.initDisplayMode(VideoControl.USE_DIRECT_VIDEO, this);
		try {
			vc.setDisplayLocation(2, 2);
			vc.setDisplaySize(width - 4, height - 4);
			//vc.setDisplaySize(50, 50);
			
		} catch (MediaException me) {
			try { vc.setDisplayFullScreen(true); }
			catch (MediaException me2) {}
			
		}
		vc.setVisible(true);
		//vc.getS
	}

	/**
	 * Paints white border
	 * @param g
	 */
	public void paint(Graphics g) {
		int width = getWidth();
		int height = getHeight();

		g.setColor(0x000000);
		g.fillRect(0, 0, width, height);
		g.setColor(0xffffff);
		g.drawRect(0, 0, width - 1, height - 1);
		g.drawRect(1, 1, width - 3, height - 3);

	}

}
